const Koa = require("koa");
const static = require("koa-static");
const Router = require("koa-router");
const axios = require("axios");
const koaServerHttpProxy = require("koa-server-http-proxy");
// const 
let app = new Koa();
app.use(koaServerHttpProxy("/api",{
    target:"http://localhost:4000",
    pathRewrite:{'^/api':''},
    changeOrigin:true
}));


app.use(static(__dirname+"/static"));
let router = new Router();

router.get("/getdata",async ctx=>{
    // axios.get("http://localhost:4000/test").then(res=>{
    //     console.log(res.data);
    // })
    let {data} = await axios.get("http://localhost:4000/test")
    ctx.body = data;
})

app.use(router.routes());
app.listen(3000);